#ifndef GFX_TILEMAP_H
#define GFX_TILEMAP_H

#include "gfx_core.h"
#include "gfx_image.h"
#include "gfx_sprite.h"


//-----------------------------------------------------------------------------
// Tilemap
//-----------------------------------------------------------------------------


/**
 * \brief Structure for rendering a tilemap.
 */
typedef struct
{
    float x, y;
    int width, height;

    GFX_Image *image;

    int *tiles;
    int numberOfTiles;

} GFX_Tilemap;

/**
 * \brief Create a tilemap.
 * \param image
 * \param width Width of the tilemap
 * \param height Height of the tilemap
 * \return The tilemap, filled with zeroes.
 */
GFX_Tilemap* gfx_tilemap_create(const char *image, int width, int height);

/**
 * \brief Free a tilemap.
 * \param tilemap Tilemap to free
 */
void gfx_tilemap_delete(GFX_Tilemap *tilemap);

/**
 * \brief Set the value of a tile.
 * \param t Tilemap
 * \param x
 * \param y
 * \param tile New value of the tile
 */
void gfx_tilemap_set_tile(GFX_Tilemap *t, int x, int y, int tile);

/**
 * \brief Fill a rectangle with a tile.
 * \param t Tilemap
 * \param x
 * \param y
 * \param w
 * \param h
 * \param tile
 */
void gfx_tilemap_set_tiles(GFX_Tilemap *t, int x, int y, int w, int h, int tile);

int gfx_tilemap_get_tile(GFX_Tilemap *t, int x, int y);
void gfx_tilemap_generate(GFX_Tilemap *t);
GFX_Tilemap* gfx_tilemap_read(const char *filename);

void gfx_render_tilemap(GFX_Tilemap *tilemap);

#endif
